//public class Sell implements Runnable {
//    private int tickets = 100;
//    private final Object lock = new Object();
//    @Override
//    public void run() {
//        while (true) {
//            synchronized (lock) {
//                if (tickets > 0) {
//
//                }
//            }
//        }
//    }
//}
//
//class TestSell {
//    public static void main(String[] args) {
//        Sell sell = new Sell();
//        new Thread(sell).start();
//        new Thread(sell).start();
//        new Thread(sell).start();
//        new Thread(sell).start();
//    }
//}

public class Sell implements Runnable {
    private int tickets = 100;

    @Override
    public void run() {
        while (tickets > 0) {
            try {
                Thread.sleep(1);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }

            tickets--;
            System.out.println(Thread.currentThread().getName() + ": 还有 " + tickets + " 张票");
        }
    }

}

class TestSell {
    public static void main(String[] args) {
        Runnable runnable = new Sell();
        Thread[] threads = new Thread[5];
        for (int i = 0; i < threads.length; i++) {
            threads[i] = new Thread(runnable);
            threads[i].start();
        }
    }
}